<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户昵称" prop="nickName">
        <el-input v-model="queryParams.nickname" placeholder="请输入用户昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="反馈内容" prop="content">
        <el-input v-model="queryParams.content" placeholder="请输入反馈内容" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="手机号码" prop="contact">
        <el-input v-model="queryParams.contact" placeholder="请输入手机号码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['surveys:users:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="adviseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户ID" align="center" prop="uid" />
      <el-table-column label="用户昵称" align="center" prop="nickname" />
      <el-table-column label="反馈内容" align="center" prop="content">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" placement="top">
            <template slot="content">
              <div style="max-width: 500px;">{{  scope.row.content  }}</div>
            </template>
            <div class="surverys-desc">{{ scope.row.content }}</div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="联系方式" align="center" prop="contact" />
      <el-table-column label="提交时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="handleInfo(scope.row)" v-hasPermi="['surveys:users:info']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['surveys:users:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
      <el-dialog
        title="详情"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose"
      >
        <div class="info-line">
          <span>用户昵称: </span>
          <span>{{ recordData.nickname }}</span>
        </div>
        <div class="info-line">
          <span>联系方式: </span>
          <span>{{ recordData.contact }}</span>
        </div>
        <div class="info-line">
          <span>反馈内容: </span>
          <span class="info-content">{{ recordData.content }}</span>
        </div>
      </el-dialog>

  </div>
</template>

<script>
import { listAdvise, delAdvise } from "@/api/surveys/usersAdvise";

export default {
  name: "Answers",
  data() {
    return {
      dialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户数据
      adviseList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickname: null,
        contact: null,
        content: '',
      },
      recordData: {},
    };
  },
  created() {
    this.getList();
  },
  computed: {
  },
  methods: {
    handleClose () {
      this.dialogVisible = false;
    },
    // 查看详情
    handleInfo (row) {
      this.recordData = row;
      this.dialogVisible = true;
    },
    /** 查询意见反馈列表 */
    getList() {
      this.loading = true;
      listAdvise(this.queryParams).then(response => {
        this.adviseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => {
        return item.id
      })
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let ids = null;
      if (row.id) {
        ids = [row.id]
      } else {
        ids = this.ids
      }
      this.$modal.confirm('是否确认删除？').then(function () {
        return delAdvise(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
  }
};
</script>

<style scoped>
.surverys-desc {
  word-break: break-all;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.el-tooltip__popper {
  width: max-content;
}
.info-line {
  margin-bottom: 10px;
}
.info-content {
  line-height: 24px;
}
</style>